package com.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 王霄
 * @date 2022/1/8 17:43
 */
@Configuration
public class TopicConfig {

    public static final String EXCHANGE_NAME = "topic.exchange";
    public static final String QUEUE1 = "topic.queue1";
    public static final String QUEUE2 = "topic.queue2";

    @Bean(EXCHANGE_NAME)
    public TopicExchange topicExchange() {
        return new TopicExchange(EXCHANGE_NAME);
    }

    @Bean(QUEUE1)
    public Queue queue1() {
        return new Queue(QUEUE1);
    }

    @Bean(QUEUE2)
    public Queue queue2() {
        return new Queue(QUEUE2);
    }

    @Bean
    public Binding topicBindingOne() {
        return BindingBuilder
                .bind(queue1())
                .to(topicExchange())
                .with("baidu.#");
    }

    @Bean
    public Binding topicBindingTwo() {
        return BindingBuilder
                .bind(queue2())
                .to(topicExchange())
                .with("google.#");
    }

    @Bean
    public Binding topicBindingThree() {
        return BindingBuilder
                .bind(queue2())
                .to(topicExchange())
                .with("baidu.*");
    }
}
